<?php

use yii\helpers\Url;
use backend\components\helper\EasyHtml;
use backend\components\widget\adminLTE\GridView;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '缓存管理';
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="row">
    <div class="col-xs-12">
        <div class="box box-primary">
            <div class="box-header with-border">
                <h3 class="box-title"><?= EasyHtml::encode($this->title) ?></h3>
                <div class="box-tools pull-right">
                    <?= EasyHtml::iconLink('清空缓存', ['cache','type'=>1], [
                        'icon' => 'trash-o',
                        'class' => 'btn btn-danger',
                        'data' => [
                            'confirm' => '您确定要清空缓存吗？'
                        ]
                    ]) ?>
                    <?= EasyHtml::iconLink('清空表缓存', ['cache','type'=>2], [
                        'icon' => 'trash-o',
                        'class' => 'btn btn-warning',
                        'data' => [
                            'confirm' => '您确定要清空全部表缓存吗？'
                        ]
                    ]) ?>
                    <?= EasyHtml::iconLink('清空assets', ['cache','type'=>4], [
                        'icon' => 'trash-o',
                        'class' => 'btn btn-info',
                        'data' => [
                            'confirm' => '您确定要清空assets缓存吗？'
                        ]
                    ]) ?>
                </div>
            </div>

            <div class="box-tools">
                <div class="box-body">
                    <p class="text-warning text-center">
                        <span><i class="fa fa-warning"></i></span>
                        Mysql配置schemaCacheDuration为true时,点击删除更新表结构缓存.
                    </p>
                    <?= GridView::widget([
                        'id' => 'data-base-table',
                        'dataProvider' => $dataProvider,
                        'columns'      => [
                            ['class' => 'yii\grid\SerialColumn', 'header' => '序号'],
                            [
                                'label' => '表名',
                                'value' => function($model){
                                    return $model['Name']??'';
                                },
                            ],
                            [
                                'label' => '存储引擎',
                                'value' => function($model){
                                    return $model['Engine']??'';
                                },
                            ],
                            [
                                'label' => '排序规则',
                                'value' => function($model){
                                    return $model['Collation']??'';
                                },
                            ],
                            [
                                'label' => '版本',
                                'value' => function($model){
                                    return $model['Version']??'';
                                },
                            ],
                            [
                                'label' => '行格式',
                                'value' => function($model){
                                    return $model['Row_format']??'';
                                },
                            ],
                            [
                                'label' => '表行数',
                                'value' => function($model){
                                    return $model['Rows']??'';
                                },
                            ],
                            [
                                'label' => '表大小',
                                'value' => function($model){
                                    return app()->formatter->asShortSize($model['Data_length']??'');
                                },
                            ],
                            [
                                'label' => '索引大小',
                                'value' => function($model){
                                    return app()->formatter->asShortSize($model['Index_length']??'');
                                },
                            ],
                            [
                                'label' => '表备注',
                                'value' => function($model){
                                    return $model['Comment']??'';
                                },
                            ],
                            [
                                'class' => 'backend\components\widget\adminLTE\ActionColumn',
                                'template' => '{delete}',
                                'buttons' => [
                                    'delete' => function($url, $model, $key){
                                        return  EasyHtml::iconLink('删除缓存', ['cache','type'=>3,'tableName'=>$model['Name']], [
                                            'icon' => 'trash-o',
                                            'class' => 'btn btn-xs btn-danger',
                                            'data' => [
                                                'confirm' => '您确定要删除此表结构缓存吗？'
                                            ]
                                        ]);
                                    }
                                ],
                            ],
                        ],
                    ]); ?>
                </div>
            </div>
        </div>
    </div>
</div>